﻿/*
 * Copyright (c) United Binary LLC.  All rights reserved.
 * 
 * This code is licensed under the MIT License
 * 
 * SEE: http://harnessit.codeplex.com/license
 * 
 */
using System;
using UnitedBinary.UnitTests.Framework;
using System.Drawing;

namespace UnitedBinary.HarnessIt.UnitTests.TestBasis
{
	//public static class EX
	//{
	//	public static bool IsPositive<T>(this T num) where T : struct
	//	{
	//		return num > 0;
	//	}
	//}
	public class ExpressionsTests
	{
		[TestMethod]
		public void StringTests(ITest it)
		{
			string x = "first";
			string y = "first";
			string z = "notfirst";
			it.Are.Equal( x, y, "They should be the same" );
			it.Are.Equal( x, y );

			it.Are.NotEqual( x, z );
			it.Are.NotEqual( x, z, "Not the same" );

			it.Are.Equal( x.ToLower(), y.ToUpper(), true );
			it.Are.NotEqual( x, z, true );
		}

		[TestMethod]
		public void IntTests(ITest it)
		{
			int x = 7;
			int y = x;
			int z = x+1;
			it.Are.Equal( x, y, "They should be the same" );
			it.Are.Equal( x, y);

			it.Are.NotEqual( x, z);
			it.Are.NotEqual( x, z, "Not the same" );
		}

		[TestMethod]
		public void UIntTests(ITest it)
		{
			uint x = 7;
			uint y = x;
			uint z = x + 1;
			it.Are.Equal( x, y, "They should be the same" );
			it.Are.Equal( x, y );

			it.Are.NotEqual( x, z );
			it.Are.NotEqual( x, z, "Not the same" );
		}

		[TestMethod]
		public void LongTests(ITest it)
		{
			long x = 7;
			long y = x;
			long z = y+1;
			it.Are.Equal( x, y, "They should be the same" );
			it.Are.Equal( x, y );

			it.Are.NotEqual( x, z);
			it.Are.NotEqual( x, y + 1, "Not the same" );
		}

		[TestMethod]
		public void ULongTests(ITest it)
		{
			ulong x = 7;
			ulong y = x;
			ulong z = y + 1;
			it.Are.Equal( x, y, "They should be the same" );
			it.Are.Equal( x, y );

			it.Are.NotEqual( x, z );
			it.Are.NotEqual( x, y + 1, "Not the same" );
		}

		[TestMethod]
		public void ShortTests(ITest it)
		{
			short x = 7;
			short y = x;
			short z = (short)(y + 1);
			it.Are.Equal( x, y, "They should be the same" );
			it.Are.Equal( x, y );

			it.Are.NotEqual( x, z);
			it.Are.NotEqual( x, z, "Not the same" );
		}

		[TestMethod]
		public void UShortTests(ITest it)
		{
			ushort x = 7;
			ushort y = x;
			ushort z = (ushort)(y + 1);
			it.Are.Equal( x, y, "They should be the same" );
			it.Are.Equal( x, y );

			it.Are.NotEqual( x, z);
			it.Are.NotEqual( x, z, "Not the same" );
		}

		[TestMethod]
		public void DateTimeTests(ITest it)
		{
			DateTime x = DateTime.Now;
			DateTime y = x;
			DateTime z = x.AddMilliseconds( 1 );
			it.Are.Equal( x, y, "They should be the same" );
			it.Are.Equal( x, y );

			it.Are.NotEqual( x, z );
			it.Are.NotEqual( x, z, "Not the same" );
		}

		[TestMethod]
		public void DecimalTests(ITest it)
		{
			decimal x = (decimal)7.10000001;
			decimal y = (decimal)7.10000002;
			decimal z = (y + 1);
			decimal delta = 0.00001M;
			it.Are.Equal( x, y, delta, "They should be the same" );
			it.Are.Equal( x, y, delta );

			it.Are.NotEqual( x, z, delta );
			it.Are.NotEqual( x, z, delta, "Not the same" );
		}

		[TestMethod]
		public void DoubleTests(ITest it)
		{
			double x = 7.10000001;
			double y = 7.10000002;
			double z = (y + 1);
			double delta = 2 * (x - y);
			it.Are.Equal( x, y, delta, "They should be the same" );
			it.Are.Equal( x, y, delta );

			it.Are.NotEqual( x, z, delta );
			it.Are.NotEqual( x, z, delta, "Not the same" );
		}

		[TestMethod]
		public void FloatTests(ITest it)
		{
			float x = 7.1001f;
			float y = 7.1002f;
			float z = (y + 1);
			float delta = 2 * (x - y);
			it.Are.Equal( x, y, delta, "They should be the same" );
			it.Are.Equal( x, y, delta );

			it.Are.NotEqual( x, z, delta );
			it.Are.NotEqual( x, z, delta, "Not the same" );
		}

		[TestMethod]
		public void PointTests(ITest it)
		{
			Point x = new Point( 1, 2 );
			Point y = new Point( 1, 2 );
			Point z = new Point( 2, 2 );
			it.Are.Equal( x, y, "They should be the same" );
			it.Are.Equal( x, y);

			it.Are.NotEqual( x, z);
			it.Are.NotEqual( x, z, "Not the same" );
		}

		[TestMethod]
		public void SizeTests(ITest it)
		{
			Size x = new Size( 1, 2 );
			Size y = new Size( 1, 2 );
			Size z = new Size( 2, 2 );
			it.Are.Equal( x, y, "They should be the same" );
			it.Are.Equal( x, y );

			it.Are.NotEqual( x, z );
			it.Are.NotEqual( x, z, "Not the same" );
		}

		[TestMethod]
		public void SizeFTests(ITest it)
		{
			SizeF x = new SizeF( 1.001f, 2 );
			SizeF y = new SizeF( 1, 2.001f );
			SizeF z = new SizeF( 2, 2 );
			float delta = 0.01f;
			it.Are.Equal( x, y, delta, "They should be the same" );
			it.Are.Equal( x, y, delta );

			it.Are.NotEqual( x, z, delta );
			it.Are.NotEqual( x, z, delta, "Not the same" );
		}

		[TestMethod]
		public void PointFTests(ITest it)
		{
			PointF x = new PointF( 1.001f, 2 );
			PointF y = new PointF( 1, 2.001f );
			PointF z = new PointF( 2, 2 );
			float delta = 0.01f;
			it.Are.Equal( x, y, delta, "They should be the same" );
			it.Are.Equal( x, y, delta );

			it.Are.NotEqual( x, z, delta );
			it.Are.NotEqual( x, z, delta, "Not the same" );
		}

		[TestMethod]
		public void RectangleTests(ITest it)
		{
			Rectangle x = new Rectangle( 1, 2, 3, 4 );
			Rectangle y = new Rectangle( 1, 2, 3, 4 );
			Rectangle z = new Rectangle( 2, 2, 3, 4 );
			it.Are.Equal( x, y, "They should be the same" );
			it.Are.Equal( x, y );

			it.Are.NotEqual( x, z );
			it.Are.NotEqual( x, z, "Not the same" );
		}

		[TestMethod]
		public void RectangleFTests(ITest it)
		{
			RectangleF x = new RectangleF( 1.001f, 2, 3, 4 );
			RectangleF y = new RectangleF( 1, 2, 3.001f, 4 );
			RectangleF z = new RectangleF( 2, 2, 3, 4 );
			float delta = 0.01f;

			it.Are.Equal( x, y, delta, "They should be the same" );
			it.Are.Equal( x, y, delta );

			it.Are.NotEqual( x, z, delta );
			it.Are.NotEqual( x, z, delta, "Not the same" );
		}

		[TestMethod]
		public void GuidTests(ITest it)
		{
			Guid x = Guid.NewGuid();
			Guid y = new Guid( x.ToString() );
			Guid z = Guid.NewGuid();
			it.Are.Equal( x, y, "They should be the same" );
			it.Are.Equal( x, y );

			it.Are.NotEqual( x, z );
			it.Are.NotEqual( x, z, "Not the same" );
		}

		[TestMethod]
		public void IsTests(ITest it)
		{
			it.Is.True( true );
			it.Is.True( true, "Is true?" );

			it.Is.False( false );
			it.Is.False( false, "Is false?" );

			it.Is.Null( null );
			it.Is.Null( null, "null?" );
			
			it.Is.NotNull( "Hello" );
			it.Is.NotNull( "Hello", "not null?" );
		}
	}
}
